//
//  NvProceduceTableViewCell.m
//  NvSellerShow
//
//  Created by dx on 17/1/19.
//  Copyright © 2017年 Meicam. All rights reserved.
//

#import "NvProcedureTableViewCell.h"
#import "NvMakeFilmClipModel.h"
#import "Utils.h"

@interface NvProcedureTableViewCell()<UIScrollViewDelegate>

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *imageViewWidth;

@property (assign, nonatomic) BOOL issendNotification;//是否发送了

@end
@implementation NvProcedureTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    self.scrollview.contentSize = CGSizeMake(self.width_LL+96, 144);
    self.scrollview.delegate = self;
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(resetOffset:) name:@"kResetScrollViewOffsetNotifacation" object:nil];
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    if (scrollView.contentOffset.x>0) {
        self.isshow = YES;
        if (!self.issendNotification) {
            [self sendNotification];
        }
    } else {
        self.isshow = NO;
        self.issendNotification = NO;
    }
}

- (void)sendNotification {
    [[NSNotificationCenter defaultCenter] postNotificationName:@"kResetScrollViewOffsetNotifacation" object:self.scrollview];
    self.issendNotification = YES;
}

- (void)resetOffset:(NSNotification *)notification {
    if (self.isshow&&self.scrollview!=notification.object) {
        [self.scrollview setContentOffset:CGPointZero animated:YES];
    }
}

- (void)updateConstraints {
    self.imageViewWidth.constant = self.width_LL-48;
    [super updateConstraints];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (IBAction)clean:(id)sender {
    if(self.delegate != nil && [self.delegate respondsToSelector:@selector(nvProcedureTableViewCell:cleanClipForNvMakeFilmClipModel:)] ==YES){
        [self.delegate nvProcedureTableViewCell:self cleanClipForNvMakeFilmClipModel:self.clipModel];
    }
}

- (IBAction)editCaption:(id)sender {
    if(self.delegate != nil && [self.delegate respondsToSelector:@selector(nvProcedureTableViewCell:editCapationForNvMakeFilmClipModel:)] ==YES){
        [self.delegate nvProcedureTableViewCell:self editCapationForNvMakeFilmClipModel:self.clipModel];
    }
}

- (IBAction)trimClip:(id)sender {
    if(self.delegate != nil && [self.delegate respondsToSelector:@selector(nvProcedureTableViewCell:trimClipForNvMakeFilmClipModel:)] ==YES){
        [self.delegate nvProcedureTableViewCell:self trimClipForNvMakeFilmClipModel:self.clipModel];
    }
}

- (IBAction)cutto:(id)sender {
    if (self.delegate != nil && [self.delegate respondsToSelector:@selector(nvProcedureTableViewCell:cuttoCapationForNvMakeFilmClipModel:)]) {
        [self.delegate nvProcedureTableViewCell:self cuttoCapationForNvMakeFilmClipModel:self.clipModel];
    }
}

- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}
@end
